﻿using System;
using System.Web.UI.WebControls;
using System.Web.Security;

public partial class admin_Create_Client : System.Web.UI.Page {
    protected void Page_Load(object sender, EventArgs e) {

    }

    protected void FormViewCreateClient_ItemInserted(object sender, FormViewInsertedEventArgs e) {
        var client_id = FormViewCreateClient.FindControl("client_idTextBox") as TextBox;
        Server.Transfer("View_Client.aspx?client_id=" + client_id.Text);
    }

    protected void InsertCancelButton_Click(object sender, EventArgs e) {
        Server.Transfer("Mng_Client.aspx");
    }

    protected void LoginStatus1_LoggingOut(object sender, LoginCancelEventArgs e)
    {
        Session.Contents.Remove("UserDetails");
        Session.Abandon();
        Session.Contents.RemoveAll();
        FormsAuthentication.SignOut();
        Response.Redirect("../Default.aspx");
    }
    protected void ClientObjectDataSource_Inserting(object sender, ObjectDataSourceMethodEventArgs e)
    {
//        var tb_expired = (TextBox)FormViewCreateClient.FindControl("licenced_expiredTextBox");
//        string text_expired = tb_expired.Text;
//        if (!text_expired.Equals(string.Empty))
//        {
//            var dateInfo = new System.Globalization.DateTimeFormatInfo();
//
//            dateInfo.ShortDatePattern = "dd/MM/yyyy";
//            var dt_expired = Convert.ToDateTime(text_expired, dateInfo);
//            e.InputParameters["licenced_expired"] = dt_expired.Date.ToString();
//        }
    }

    protected void Client_Inserting(object sender, FormViewInsertEventArgs e)
    {
        var tb = (TextBox)FormViewCreateClient.FindControl("date_registeredTextBox");

        string text = tb.Text;
        var dateInfo = new System.Globalization.DateTimeFormatInfo();

        dateInfo.ShortDatePattern = "dd/MM/yyyy";
        if (text != string.Empty)
        {
            var dt = Convert.ToDateTime(text, dateInfo);
            e.Values["date_registered"] = dt.Date.ToString();
        }
        var tb_expired = (TextBox)FormViewCreateClient.FindControl("licenced_expiredTextBox");
        string text_expired = tb_expired.Text;
        if (!text_expired.Equals(string.Empty))
        {
            var dt_expired = Convert.ToDateTime(text_expired, dateInfo);
            e.Values["licenced_expired"] = dt_expired.Date.ToString();
        }
    }
}
